<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<!DOCTYPE html>
<html>

	<head>

		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">

		<title><?=SYSTEM_TITLE?></title>

		<link href="<?=base_url("assets/css/bootstrap.min.css")?>" rel="stylesheet">
		<link href="<?=base_url("assets/font-awesome/css/font-awesome.css")?>" rel="stylesheet">

		<!-- Toastr style -->
		<link href="<?=base_url("assets/css/plugins/toastr/toastr.min.css")?>" rel="stylesheet">

		<link href="<?=base_url("assets/css/animate.css")?>" rel="stylesheet">
		<link href="<?=base_url("assets/css/style.css")?>" rel="stylesheet">

		<link href="<?=base_url("assets/css/plugins/dataTables/datatables.min.css")?>" rel="stylesheet">
		<link href="<?=base_url("assets/css/plugins/jasny/jasny-bootstrap.min.css")?>" rel="stylesheet">
				
	</head>

	<body>

		<?$this->load->view("templates/header")?>

        <div class="wrapper wrapper-content animated fadeInRight">
            <div class="row">
				<div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>活动管理</h5>
                    </div>
                    <div class="ibox-content">
						<div class="row">
							<form action="<?=site_url("main/activities_management")?>" method="get">
                                <div class="col-sm-6 col-xs-offset-2">
                                    <div class="form-group">
                                        <div class="fg-line">
                                            <input type="text" class="form-control" name="keyword" value="<?=$keyword?>" placeholder="请输入要搜索的关键字">
                                        </div>
                                    </div>
                                </div>
                                <div class="col-sm-4">
                                    <button class="btn btn-primary" style="margin-left:15px"> 搜索</button>
									<a class="btn btn-success" style="margin-left:15px" href="<?=site_url("main/activity/-1")?>"> + 新增活动 + </a>
									<a class="btn btn-success duijiang" href="javascript:void(0)"> + 兑奖功能 + </a>
                                </div>
                            </form>
						</div>   
						<div class="row m-t-lg">
							<div class="col-sm-12">
								<table class="table table-striped">
									<thead>
									<tr>
										<th>背景海报</th>
										<th>活动标题</th>
										<th>活动日期</th>
										<th>开始时间</th>
										<th>结束时间</th>
										<th>竞猜电影</th>
										<th>活动状态</th>
										<th>前日票房</th>
										<th>当日票房</th>
										<th>参与人数</th>
										<th>操作</th>
									</tr>
									</thead>
									<tbody>
									<?foreach($objects as $o){?>
									<tr>
										<td><img src="<?=base_url("upload/".$o["act_background"])?>" class="img-rounded" style="width:100px"/></td>
										<td><?=$o["act_title"]?></td>
										<td><?=$o["act_date"]?></td>
										<td><?=$o["act_start_time"]?>:00</td>
										<td><?=$o["act_end_time"]?>:00</td>
										<td><?=$o["act_movie"]?></td>
										<td><?
										switch($o["act_status"])
										{
												case 0:echo "即将开始";break;
												case 1:echo "进行中";break;
												case 2:echo "已结束";break;
										}
										?></td>
										<td><?=$o["act_yesterday"]?></td>
										<td><?=$o["act_result"]?></td>
										<td><?=$o["act_count"]?></td>
										<td>
											<a class="btn btn-xs btn-primary waves-effect waves-float" href="<?=site_url("main/activity/".$o["act_id"])?>">
											<i class="zmdi zmdi-edit"></i> 编辑</a>
											
											<a class="btn btn-xs btn-danger waves-effect waves-float" href="<?=site_url("main/delete_activity/".$o["act_id"])?>">
											<i class="zmdi zmdi-delete"></i> 删除</a>
										</td>

									</tr>
									<?}?>
									</tbody>
								</table>
								<?=$this->pagination->create_links();?>
							</div>
						</div>
						
					</div>
				</div>
            </div>
		</div>
		<div class="modal fade" id="modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
		  <div class="modal-dialog" role="document">
			<div class="modal-content">
			  <div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
				<h4 class="modal-title" id="myModalLabel">兑奖</h4>
			  </div>
			  <div class="modal-body">
				<div class="form-group">
					<label class="col-sm-3 control-label">输入兑奖码</label>
					<div class="col-sm-3">
					<select style="width:100%" id="act_id">
					<?foreach($objects as $o){?>
					<option value="<?=$o["act_id"]?>"><?=$o["act_title"]?></option>
					<?}?>
					</select>
					</div>
					<div class="col-sm-4"><input type="text" class="form-control" id="code"></div>
					<a class="col-sm-2 btn btn-primary querycode" href="javascript:void(0)">查询</a>
				</div>
				<div class="users">
				</div>
			  </div>
			  <div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-primary sbmt">标注为已兑奖</button>
			  </div>
			</div>
		  </div>
		</div>
		<?$this->load->view("templates/footer")?>

		<!-- Mainly scripts -->
		<script src="<?=base_url("assets/js/jquery-3.1.1.min.js")?>"></script>
		<script src="<?=base_url("assets/js/bootstrap.min.js")?>"></script>
		<script src="<?=base_url("assets/js/plugins/metisMenu/jquery.metisMenu.js")?>"></script>
		<script src="<?=base_url("assets/js/plugins/slimscroll/jquery.slimscroll.min.js")?>"></script>

		<!-- Custom and plugin javascript -->
		<script src="<?=base_url("assets/js/inspinia.js")?>"></script>
		<script src="<?=base_url("assets/js/plugins/pace/pace.min.js")?>"></script>
		
		<script src="<?=base_url("assets/js/plugins/jasny/jasny-bootstrap.min.js")?>"></script>
		
		<!-- Toastr script -->
		<script src="<?=base_url("assets/js/plugins/toastr/toastr.min.js")?>"></script>


		<script>
		var lucky = [];
		$(document).ready(function(){
			$(".duijiang").click(function(){
				$("#modal").modal("show");
			});

			$(".querycode").click(function(){
				$.get("<?=site_url("main/get_by_code")?>/"+$("#act_id").val()+"/"+$("#code").val(),function(data){
					console.log(data);
					lucky = data.guesses;
					var html = "";
					for(var i=0;i<lucky.length;i++)
					{
						html+="<img src='";
						html+=lucky[i].avatarUrl;
						html+="' class='img-lg'>";
						html+="<p>"+lucky[i].nickName+"</p>";
					}
					$(".users").html(html);
				})
			});
			
			$(".sbmt").click(function(){
				for(var i=0;i<lucky.length;i++)
				{
					$.get("<?=site_url("main/code_validate")?>/"+lucky[i].gus_id);
				}
				$(".users").html("");
				$("#code").val("");
				$("#modal").modal("hide");
			});
		});

		</script>
		<?$this->load->view("templates/script")?>
	</body>

</html>
